<template>
  <el-button size="small" @click="dialogVisible = true">
    添加
  </el-button>

  <el-dialog
      v-model="dialogVisible"
      width="280"
      :before-close="handleClose"
      :append-to-body="true"
      draggable
  >
    <template #header>
      <div class="text-center">申请加好友</div>
    </template>
    <div class="flex">
      <el-avatar :size="50" :src="add_user.avater"/>
      <div class="flex *:w-full flex-wrap ml-2 text-[12px] items-center">
        <div>{{ add_user.name }}</div>
        <div>{{ add_user.account }}</div>
      </div>
    </div>
    <div class="mt-2">
      <div class="">填写验证信息</div>
      <div class="m-1">
        <el-input
            v-model="add_user_obj.check_content"
            style="width: 240px"
            :rows="2"
            type="textarea"
        />
      </div>
    </div>
    <div>
      <div class="mt-1">备注</div>
      <div class="m-1">
        <el-input v-model="add_user_obj.remake"/>
      </div>
    </div>
    <div>
      <div class="mt-1">分组</div>
      <div class="m-1">
        <el-select
            v-model="add_user_obj.group"
            placeholder="好友 朋友"
            style="width: 240px"
        >
          <el-option
              v-for="item in user.groups"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </div>
    </div>
    <div>
      <div class="mt-1">权限设置</div>
      <div class="flex justify-between items-center">
        <div class="m-2">不让他看我的动态</div>
        <el-switch v-model="add_user_obj.is_look" />
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">
          发送
        </el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import {ref} from 'vue'
import {ElMessageBox} from 'element-plus'
import {useIndexStore, useUserStore} from "~/store";
import {storeToRefs} from "pinia";

const props = defineProps(['add_user'])
const {add_user} = props

const indexStore = useIndexStore()
const userStore = useUserStore()

const {user, add_user_obj} = storeToRefs(userStore)

const dialogVisible = ref(false)

const handleClose = (done: () => void) => {
  dialogVisible.value = false
}
onMounted(() => {
  add_user_obj.value.check_content = `我是${user.value.name}`
  add_user_obj.value.remake = add_user.name
  add_user_obj.value.group = '好友'
})
</script>